﻿using ACGN.Core.Repository;
using ACGN.MVC.Models;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using ACGN.Core.Models;
using ACGN.Application.Newsflashs;
using ACGN.Application.Newsflashs.Dtos;
using ACGN.Mvc.Controllers;
using ACGN.MVC.Models.Newsflashss;
using AutoMapper;

namespace ACGN.MVC.Controllers
{
    public class HomeController : BaseController
    {
        private readonly ILogger<HomeController> _logger;
        private readonly IRepository<Newsflash, int> _repository;
        private readonly INewsflashService _newsflashService;
        private readonly IMapper _mapper;

        public HomeController(ILogger<HomeController> logger, 
            IRepository<Newsflash, int> repository,
            INewsflashService newsflashService,
            IMapper mapper
            )
        {
            _logger = logger;
            _repository = repository;
            _newsflashService = newsflashService;
            _mapper = mapper;
        }

        public IActionResult Index()
        {
            return View();
        }
        public async Task<IActionResult> List(NewsflashInputDto input)
        {
            var newsflash = await _newsflashService.GetPageResult(input);
            return Json(ListResult(_mapper.Map<List<NewsflashViewModel>>(newsflash.Data), newsflash.TotalCount));
        }
        public IActionResult Privacy()
        {
            return View();
        }

        [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
        public IActionResult Error()
        {
            return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
        }
    }
}
